<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="theme/style.css"
	media="screen" />
<title>OES - Forgot Password</title>
<script language="javascript">

	var xmlHttp;// global instance of XMLHttpRequest
	function createXmlHttpRequest()
	{
	       if(window.ActiveXObject)
	       {
	        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	      }
	
	    else if(window.XMLHttpRequest)
	    {
	        xmlHttp=new XMLHttpRequest();
	     }
	
	}

	function getSecurityQuestion()
	{
	  createXmlHttpRequest();

	  var u1=document.fm.userName.value;
	  xmlHttp.open("GET","http://localhost:8082/OES/ForgotPassword.do?userName="+u1 ,true);
	  xmlHttp.onreadystatechange=handleStateChange;
	  xmlHttp.send(null);
	}

	function handleStateChange()
	{
	    if(xmlHttp.readyState==4)
	    {
	        if(xmlHttp.status==200)
            {
	        	var res = xmlHttp.responseText;
	        	var msg = "";
	        	
	        	if(res!=null)
        		{
	        		msg = res;
       				document.forms['fm'].elements['submit'].disabled = false;
        		}else
       			{
       				msg = "Unable to get security question.";
        			document.forms['fm'].elements['submit'].disabled = true;
       			}
	        	
            	document.getElementById("question").innerHTML=res;
            }
	        else
	        {
	        	document.forms['fm'].elements['submit'].disabled = true;
	           alert("Error loading page "+ xmlHttp.status +":"+xmlHttp.statusText);
	        }
	    }
	}

	function userfocus() 
	{
		document.fm.userName.focus();
	}

	function check() 
	{
		var userID, securityAnswer, email;
		userID = document.fm.userName.value;
		securityAnswer = document.fm.securityAnswer.value;
		email = document.fm.emailId.value;
		
		if (userID.length < 1) 
		{
			alert("You must enter user name.");
			document.fm.userName.focus();
			return false;
		} 
		
		else if (securityAnswer.length < 1) 
		{
			alert("You must enter security answer.");
			document.fm.securityAnswer.focus();
			return false;
		}else if (email.length < 1) 
		{
			alert("You must enter email id.");
			document.fm.emailId.focus();
			return false;
		}
		
		return true;
	}
	
	function emailValidation()
	{
		var emailValue = document.getElementByName("emailId").value;
		alert(emailValue);
		var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(!emailValue.match(emailExp) || emailValue=="" )
		{
			alert("Please enter valid email.");
			document.getElementByName("emailId").focus();
			return false;
		}
		else
		{
			return true;
		}
	}
</script>
</head>
<body onload="userfocus()">
	<div id="MainWrapper">
		<jsp:include page="header.jsp" /> 
		<jsp:include page="LeftContainer.jsp" />
		<div id="MainContent">
		<center><h2>Forgot Password</h2>
			<form action="ForgotPassword.do" method="post" name="fm" onsubmit="return check()">
				<table>
					<tr><td>User Name: </td><td><input type="text" name="userName" onblur="getSecurityQuestion()"/></td></tr>
					<tr><td>Email Id: </td><td><input type="text" name="emailId" onblur="return emailValidation()"/></td></tr>
					<tr><td>Security Question: </td><td><p id="question"></p></td></tr>
					<tr><td>Security Answer </td><td><input type="password" name="securityAnswer"/></td></tr>
					<tr><td></td><td><input type="submit" name="submit" value="Submit" disabled="disabled"/></td></tr>
				</table>
			</form>
		</center>
		</div>
		<jsp:include page="footer.jsp" />
	</div>
</body>
</html>